/**
 * @file dev_valve.h
 * @brief 
 * 
 * @author dalin (dalin@open-robot.com)
 * @version 1.0
 * @date 2023-05-11
 * 
 * @copyright Copyright (c) 2023  Open Robot Tech.co, Ltd
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2023-05-11 <td>1.0     <td>dalin     <td>内容
 * </table>
 */

#ifndef DEV_VALVE_H_
#define DEV_VALVE_H_
#include "dev_config.h"
#include "cmsis_os.h"
#include "drv_gpio.h"


/* 电磁阀ID */
typedef enum{
    VALVE_0 = 0,
    VALVE_1,
    VALVE_2,
    VALVE_3,
    VALVE_4,
    VALVE_5,
    VALVE_6,
    VALVE_7,
    
    VALVE_MAX
}valveId_e;


typedef enum
{
    VALVE_ONINIT = 0,                     //  未初始化
    VALVE_NORMAL = 1,                     //  正常模式
    VALVE_HOLD = 2,                       //  维持模式
    VALVE_PERI = 3                        //  周期模式
} valveMode_e;  

typedef enum    
{   
    LOW = 0,                        //  LOW
    HIGH = 1,                       //  HIGH
} valveState_e; 

typedef enum    
{   
    ONCE_TIME = 0,                  //  运行一次
    PERI_TIME = 1,                  //  周期循环
} valveTimerMode_e;

typedef struct
{
    char name[20];
    gpioDrv_t gpio;
}devValveConfig_t;

/* 单独设备定义 */
typedef struct
{
    bool            enable;         // 使能状态
    valveMode_e     mode;           // 当前模式
    uint8_t         state;          // 当前状态
    int             time;           // 维持时间
    uint16_t        num;            // 周期运行次数
    osTimerId       timer_id;       // 维持时间软件定时器头
}valveSingle_t;

/* 整体开关设备定义 */
typedef struct
{
    bool valve_enabled;
    valveSingle_t dev[VALVE_MAX];
}devValve_t;



/************************************ api ************************************/
void dev_valve_init(void);
void dev_valve_deinit(void);

void dev_valve_enable(void);
void dev_valve_disable(void);
void dev_valve_state_control(valveId_e valve, bool state);
bool dev_valve_state_read(valveId_e id);
void dev_valve_set_mode(valveId_e id, valveMode_e mode);

void dev_valve_timer_create(valveId_e id, uint8_t mode, uint16_t time, uint8_t num);
void dev_valve_timer_destroy(valveId_e valve_id);

/************************************ test ************************************/
void dev_valve_test(void);
#endif  /* DEV_VALVE_H_ */

